package Work;

import java.util.ArrayList;
import java.util.Scanner;

public class ForeignKey {
	
	//创建数据库连接类对象
    Jdbc db = new Jdbc();

    //创建图书操作类对象
    ChangeBook changebook = new ChangeBook();
    //创建图书列表(初始数据从文件导入)
    ArrayList<Book> booklist = changebook.read(db);
    
    //创建读者操作类对象
    ChangeReader changereader = new ChangeReader();
    //创建读者列表(初始数据从文件导入)
    ArrayList<Reader> readerlist = changereader.read(db);
    
    //创建管理员操作类对象
    ChangeLibrarian changelibrarian = new ChangeLibrarian();
    //创建管理员列表(初始数据从文件导入)
    ArrayList<Librarian> librarianlist = changelibrarian.read(db);
    
    //创建借阅记录操作类对象
    ChangeRecord changerecord = new ChangeRecord();
    //创建借阅记录列表(初始数据从文件导入)
    ArrayList<Record> recordlist = changerecord.read(db);
	
	public boolean FindB_ID(ArrayList<Book> list,String s) {
		booklist = changebook.read(db);
		for(Book book:booklist) {
			if(book.getId().equals(s)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindB_NAME(ArrayList<Book> list,String s) {
		for(Book book:booklist) {
			if(book.getName().equals(s)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindB_AUTHOR(ArrayList<Book> list,String s) {
		for(Book book:booklist) {
			if(book.getAuthor().equals(s)) {
				return true;
			}
		}
		return false;
	}
	
	public boolean FindR_ID(ArrayList<Reader> list,String id) {
		for(Reader reader:readerlist) {
			if(reader.getID().equals(id)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindR_NAME(ArrayList<Reader> list,String s) {
		for(Reader reader:readerlist) {
			if(reader.getName().equals(s)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindR_NUMBER(ArrayList<Reader> list,String s) {
		for(Reader reader:readerlist) {
			if(reader.getNumber().equals(s)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindR_INSTITUTE(ArrayList<Reader> list,String s) {
		for(Reader reader:readerlist) {
			if(reader.getInstitute().equals(s)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindR_amount(ArrayList<Reader> list,String s) {
		for(Reader reader:readerlist) {
			if(reader.getAmount().equals(s)) {
				return true;
			}
		}
		return false;
	}
	
	
	public boolean FindL_ID(ArrayList<Librarian> list,String id) {
		for(Librarian librarian:librarianlist) {
			if(librarian.getID().equals(id)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindL_NAME(ArrayList<Librarian> list,String S) {
		for(Librarian librarian:librarianlist) {
			if(librarian.getName().equals(S)) {
				return true;
			}
		}
		return false;
	}
	public boolean FindL_NUMBER(ArrayList<Librarian> list,String S) {
		for(Librarian librarian:librarianlist) {
			if(librarian.getNumber().equals(S)) {
				return true;
			}
		}
		return false;
	}
	
	public boolean IfZero(ArrayList<Book> list, String id) {
		for(Book book:booklist) {
			if(book.getId().equals(id)) {
				if(book.getAmount() <= 0)
					return false;
			}
		}
		return true;
	}

}
